//
//  Welcom.m
//  ChampoinPeso
//
//  Created by mac on 2025/3/21.
//

#import "Welcom.h"
@interface Welcom()
@property (nonatomic,assign)NSInteger type;
@property (nonatomic,strong)UIView *step;
@end
@implementation Welcom

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame type:(NSInteger)type{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI:type];
    }
    return self;
}

-(void)setupUI:(NSInteger)type{
    _type = type;
    UIView *view = [UIView new];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    UIImageView *bgIV = [[UIImageView alloc] initWithFrame:view.bounds];
    if (type == 1) {
        bgIV.image = [UIImage imageNamed:@"welome_1"];
    }else if (type == 2){
        bgIV.image = [UIImage imageNamed:@"welome_2"];
    }else if (type == 3){
        bgIV.image = [UIImage imageNamed:@"welome_3"];
    }
    [view addSubview:bgIV];
    [bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    [view addSubview:self.next];
    _next.tag = _type;
    [_next mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(60);
        make.right.mas_offset(-60);
        make.height.mas_equalTo(48);
        make.bottom.mas_offset(-bottomSafeHeight-50);
    }];
    [view addSubview:self.step];
    [_step mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(view);
        make.bottom.equalTo(_next.mas_top).offset(-32);
    }];
}

-(UIButton *)next
{
    if (!_next) {
        _next = [UIButton buttonWithType:UIButtonTypeCustom];
        if (_type == 3) {
            [_next setTitle:@"start" forState:UIControlStateNormal];
            [_next setBackgroundColor:HexColor(@"#2C64FF")];
        }else{
            [_next setTitle:@"next" forState:UIControlStateNormal];
            [_next setTitleColor:HexColor(@"#2C64FF") forState:UIControlStateNormal];
        }
        _next.layer.cornerRadius = 24;
        _next.layer.borderColor = HexColor(@"#2C64FF").CGColor;
        _next.layer.borderWidth = 1;
    }
    return _next;
}

-(UIView *)step
{
    if (!_step) {
        _step = [UIView new];
        UIView *view  = [UIView new];
        [_step addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_offset(0);
        }];
        CGFloat width = 18;
        for (int i = 0; i<3; i++) {
            UIImageView *img = [UIImageView new];
            [view addSubview:img];
            [img mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(width*i+10*i);
                make.top.bottom.mas_offset(0);
                make.size.mas_offset(CGSizeMake(width, 4));
                if (i == 2 ) {
                    make.right.mas_offset(-10);
                }
            }];
            if (_type == i+1) {
                img.image = [UIImage imageNamed:@"welcome_btn2"];
            }else{
                img.image = [UIImage imageNamed:@"welcome_btn"];
            }
        }
    }
    return _step;
}
@end
